package com.ruoyi.project.system.service.impl;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.mapper.SysBusinessMapper;
import com.ruoyi.project.system.domain.SysBusiness;
import com.ruoyi.project.system.service.ISysBusinessService;

/**
 * 创业内容Service业务层处理
 *
 * @author theme
 * @date 2020-08-27
 */
@Service
public class SysBusinessServiceImpl implements ISysBusinessService {
    @Autowired
    private SysBusinessMapper sysBusinessMapper;

    /**
     * 查询创业内容
     *
     * @param businessId 创业内容ID
     * @return 创业内容
     */
    @Override
    public SysBusiness selectSysBusinessById(Long businessId) {
        return sysBusinessMapper.selectSysBusinessById(businessId);
    }

    /**
     * 查询创业内容列表
     *
     * @param sysBusiness 创业内容
     * @return 创业内容
     */
    @Override
    public List<SysBusiness> selectSysBusinessList(SysBusiness sysBusiness) {
        return sysBusinessMapper.selectSysBusinessList(sysBusiness);
    }

    /**
     * 新增创业内容
     *
     * @param sysBusiness 创业内容
     * @return 结果
     */
    @Override
    public int insertSysBusiness(SysBusiness sysBusiness) {
        sysBusiness.setCreateTime(DateUtils.getNowDate());
        return sysBusinessMapper.insertSysBusiness(sysBusiness);
    }

    /**
     * 修改创业内容
     *
     * @param sysBusiness 创业内容
     * @return 结果
     */
    @Override
    public int updateSysBusiness(SysBusiness sysBusiness) {
        sysBusiness.setUpdateTime(DateUtils.getNowDate());
        return sysBusinessMapper.updateSysBusiness(sysBusiness);
    }

    /**
     * 批量删除创业内容
     *
     * @param businessIds 需要删除的创业内容ID
     * @return 结果
     */
    @Override
    public int deleteSysBusinessByIds(Long[] businessIds) {
        return sysBusinessMapper.deleteSysBusinessByIds(businessIds);
    }

    /**
     * 删除创业内容信息
     *
     * @param businessId 创业内容ID
     * @return 结果
     */
    @Override
    public int deleteSysBusinessById(Long businessId) {
        return sysBusinessMapper.deleteSysBusinessById(businessId);
    }

    @Override
    public List<SysBusiness> selectTypeSysBusinessList(SysBusiness sysBusiness) {
        List<SysBusiness> businessList = sysBusinessMapper.selectTypeSysBusinessList(sysBusiness);
/*        Collections.sort(businessList, new Comparator<SysBusiness>() {
            @Override
            public int compare(SysBusiness o1, SysBusiness o2) {
                int T1 = Integer.parseInt(o1.getBusinessType());
                int T2 = Integer.parseInt(o2.getBusinessType());
                if (T1 > T2) {
                    return -1;
                }
                if (T1 < T2) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });*/
        return businessList;
    }
}
